using System;
using System.Diagnostics;

namespace ValidationFramework.Tests
{
	public class DisposableStopwatch:IDisposable
	{
		private readonly string message;
		private readonly int iterations;
		private	Stopwatch stopwatch;
		public DisposableStopwatch(string message, int iterations)
		{
			this.message = message;
			this.iterations = iterations;
		}

		public void Run(Action action)
		{
			stopwatch = Stopwatch.StartNew();
			for (var i = 0; i < iterations; i++)
			{
				action();
			}
		}

		public void Dispose()
		{
			stopwatch.Stop();
			var message1 = string.Format("{0} \r\n Iterations {1} \r\n Total {2} ms \r\n Single {3} ms", message, iterations, stopwatch.ElapsedMilliseconds, ((float)stopwatch.ElapsedMilliseconds) / iterations);
			Debug.WriteLine(message1);
			//MessageBox.Show(message1);
		}
	}
}